#region Namespace Declarations

using System;

#endregion Namespace Declarations

namespace RSEngine.Math
{
    /// <summary>
    ///	A standard sphere, used mostly for bounds checking.
    /// </summary>
    /// <remarks>
    ///	A sphere in math texts is normally represented by the function
    ///	x^2 + y^2 + z^2 = r^2 (for sphere's centered on the origin). We store spheres
    ///	simply as a center point and a radius.
    /// </remarks>
    public sealed class Sphere
    {

        #region Variables

        public float Radius;
        public Vector3 Center;

        #endregion

        #region Constructors

        /// <summary>
        ///	Creates a unit sphere centered at the origin.
        /// </summary>
        public Sphere()
        {
            Radius = 1.0f;
            Center = Vector3.Zero;
        }

        /// <summary>
        /// Creates an arbitrary spehere.
        /// </summary>
        /// <param name="center">Center point of the sphere.</param>
        /// <param name="radius">Radius of the sphere.</param>
        public Sphere(Vector3 center, float radius)
        {
            this.Center = center;
            this.Radius = radius;
        }

        #endregion

        #region Misc

        public static bool operator ==(Sphere sphere1, Sphere sphere2)
        {
            return sphere1.Center == sphere2.Center && sphere1.Radius == sphere2.Radius;
        }

        public static bool operator !=(Sphere sphere1, Sphere sphere2)
        {
            return sphere1.Center != sphere2.Center || sphere1.Radius != sphere2.Radius;
        }

        public override bool Equals(object obj)
        {
            return obj is Sphere && this == (Sphere)obj;
        }

        public override int GetHashCode()
        {
            return Center.GetHashCode() ^ Radius.GetHashCode();
        }

        #endregion

    }
}
